package top.wshape1.shiziapi.gateway.config;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.client.loadbalancer.reactive.ReactorLoadBalancerExchangeFilterFunction;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.reactive.function.client.WebClient;

import java.util.stream.Collectors;

/**
 * @author Wshape1
 * @version 1.0
 * @description
 * @since 2023-08-30
 */

@Configuration
public class WebConfig {

    @Bean
    public WebClient webClient(WebClient.Builder builder,
                               ReactorLoadBalancerExchangeFilterFunction loadBalancerExchangeFilterFunction) {
        return builder
                .filter(loadBalancerExchangeFilterFunction)
                .build();
    }

    @Bean
    @ConditionalOnMissingBean
    public HttpMessageConverters messageConverters(ObjectProvider<HttpMessageConverter<?>> converters) {
        return new HttpMessageConverters(converters.orderedStream().collect(Collectors.toList()));
    }


}
